{% include "iframe_header" %}


<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="searchform">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">交易对</label>
                            <div class="layui-input-inline">
                                <select name="symbol" lay-verify="required" lay-reqtext="不能为空">
                                    <option value="">请选择</option>
                                    {% range $k,$v := .all_symbols %}
                                    <option value="{%$v.Symbol%}">{%$v.Name%}/{%$v.Symbol%}</option>
                                    {%end%}
                                </select>
                            </div>
                        </div>


                        <div class="layui-inline">
                            <label class="layui-form-label">订单类型</label>
                            <div class="layui-input-inline">
                                <select name="order_type">
                                    <option value="">请选择</option>
                                    <option value="limit">Limit</option>
                                    <option value="market">Market</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">用户</label>
                            <div class="layui-input-inline">
                                <input type="text" name="user_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                         
                        
                        <div class="layui-inline">
                            <label class="layui-form-label">订单号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="order_id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        
                        <div class="layui-inline layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">全部</option>
                                    <option value="1">已成交</option>
                                    <option value="2">已取消</option>
                                </select>
                            </div>
                        </div>

                        
                        
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!-- <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button> -->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>


<script>
    layui.use(['form', 'table','element', 'miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            miniTab = layui.miniTab,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/user/order/history?api=1',
            //toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            where: {"searchParams": {% .search | json %}},
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'user_id', title: '用户ID'},
                {field: 'symbol', title: '交易对'},
                {field: 'order_id', width:200, title: '订单号', templet: function(d){
                    return '<a href="javascript:;" class="go_tradelog" symbol="'+d.symbol+'" order_id="'+d.order_id+'">'+d.order_id+'</a>'
                }},
                {field: 'order_type', title: '类型', templet:function(d){
                    return d.order_type + "/" + d.order_side;
                }},
                {field: 'price', title: '委托价格/成交均价', minWidth: 150, templet:function(d){
                    return d.price + "/" + d.avg_price;
                }},
                {field: 'quantity', title: '数量'},
                {field: 'finished_qty', title: '已成交'},
                {field: 'finished_amount', title: '成交金额'},
                {field: 'status', title: '状态', templet:function(d){
                    return utils.format_order_status(d.status);
                }},
                
                {field: 'create_time', width: 280, title: '创建时间', templet: function(d){
                    return utils.format_timestamp(d.create_time/1e6);
                }},
                
                // {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        // 监听添加操作
        $(document).on("click", ".go_tradelog", function(){
            var symbol = $(this).attr("symbol");
            var order_id = $(this).attr("order_id");

            var search = {symbol: symbol};
            if(order_id.indexOf("A") > -1){
                search["ask"] = order_id;
            }else{
                search["bid"] = order_id;
            }

            var url = "/admin/user/trade/history?searchParams="+ encodeURI(JSON.stringify(search));
            console.log(url);
            miniTab.openNewTabByIframe({title: order_id+"成交记录", href:url});
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                obj.del();
                layer.close(index);
            });
            }
        });

        form.val("searchForm", JSON.parse({% .search | json %}));
        form.render();
        
    });
</script>


{% include "iframe_footer" %}
